/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package se.sll.itintegration.catalogue.gui.service.view.offer;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.SecurityContext;

import lombok.extern.slf4j.Slf4j;

import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.cdi.CdiCamelContext;

import se.sll.itintegration.catalogue.gui.camel.cdi.CamelRoute;
import se.sll.itintegration.catalogue.gui.data.OfferView;
import se.sll.service.catalogue.common.exception.ResourceNotFoundException;
import se.sll.service.catalogue.common.exception.ServiceCatalogueException;
import se.sll.service.catalogue.common.exception.ValidationException;

/**
 *
 * @author khaleddaham
 */
@Path("/view/offer")
@Slf4j
@Stateless
public class OfferViewService {

    @Inject
    private CdiCamelContext camelCtx;
    private static final String T_MEDIA_TYPE = "application/json; charset=UTF-8";

    @GET
    @Produces(T_MEDIA_TYPE)
    @Path("/")
    public OfferView getAllView(@Context SecurityContext sc) throws ValidationException, ResourceNotFoundException, ServiceCatalogueException {
        log.trace("getAllView() ENTER");
        ProducerTemplate template = camelCtx.createProducerTemplate();
        OfferView view = (OfferView) template.sendBodyAndProperty(CamelRoute.GET_OFFER_VIEW, ExchangePattern.InOut, null, "sc", sc);
        log.trace("getAllView() EXIT");
        return view;
    }

    /**
     *
     * @param hsaId
     * @param sc
     * @return
     * @throws ValidationException
     * @throws ResourceNotFoundException
     * @throws ServiceCatalogueException
     */
    @GET
    @Path("/{hsaId}")
    @Produces(T_MEDIA_TYPE)
    public OfferView getOfferView(@PathParam("hsaId") String hsaId, @Context SecurityContext sc) throws ValidationException, ResourceNotFoundException, ServiceCatalogueException {
        log.trace("getOfferView() ENTER");
        ProducerTemplate template = camelCtx.createProducerTemplate();
        OfferView view = (OfferView) template.sendBodyAndProperty(CamelRoute.GET_ONE_OFFER_VIEW, ExchangePattern.InOut, null, "hsaId", hsaId);
        log.trace("getOfferView() EXIT");
        return view;
    }

}
